package com.ruoyi.system.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.entity.SmartReservation;
import com.ruoyi.system.domain.entity.SmartResultReservation;
import com.ruoyi.system.service.ISmartReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.web.domain.AjaxResult;

import java.util.Date;
import java.util.List;

import static com.ruoyi.common.core.utils.PageUtils.startPage;

/**
 * SmartReserationController
 * 车辆预约
 *
 * @author life.
 * @date 2025/3/25
 */
@RestController
@RequestMapping("/reservation")
public class SmartReserationController extends BaseController {
    @Autowired
    private ISmartReservationService iSmartReservationService;

/**
 * 车辆预约
 */


    /**
     * 更新预约（含设置）
     */
    @RequiresPermissions("system:reservation:update")
    @Log(title = "更新车辆预约", businessType = BusinessType.UPDATE)
    @PostMapping("/reupdate")
    public AjaxResult update(@RequestBody SmartResultReservation reservation) {
        int result = iSmartReservationService.updateReservation(reservation);
        return toAjax(result);
    }

    /**
     * 联表查询预约及停车订单
     */
    @RequiresPermissions("system:reservation:list")
    @Log(title = "联表查询预约及停车订单", businessType = BusinessType.INSERT)
    @GetMapping("/relist")
    public TableDataInfo get(
            @RequestParam(value = "scUserName", required = false) String scUserName,
            @RequestParam(value = "reservationDate", required = false) Date reservationDate,
            @RequestParam(value = "reservationStatus", required = false) Integer reservationStatus
    ) {
        startPage();
        List<SmartReservation> reservationList = iSmartReservationService.getReservationWithOrderByUserName(
                scUserName,
                reservationDate,
                reservationStatus);
        return getDataTable(reservationList);
    }
}